import  requests


class SendMethod():
    @staticmethod
    def send_method(method, url, params=None, data=None, json=None, headers=None):
        if method == 'get':
            response = requests.get(url, params=params, headers=headers)
        elif method == 'post':
            response = requests.post(url, data=data, json=json, headers=headers)
        else:
            response=None
            print('请求发送错误,请重新选择')

        result = {}  # 将响应结果放入字典中
        if response is not None:  # 判断respone是否为空
            result['status_code'] = response.status_code  # 获得响应状态码
            result['headers'] = response.headers  # 获取响应头
            result['body'] = response.json()  # 获取响应体
            result['respone_time'] = int(response.elapsed.microseconds / 1000)  # 获得响应时间
            return result
        else:
            return response

if __name__ == '__main__':
    method ='post'
    url ='http://47.108.206.100:8080/admin/login'
    login_data={
        'username':'admin',
        'password':'macro123'
    }
    print(SendMethod.send_method(method, url, json=login_data))

